<header class="main-box-header clearfix">
	<div class="row m-b-sm m-t-sm">
		<div class="col-md-8">
			<button id="infoAddBtn" th:href="@{/admin/m/base/info/add_{nodeId}.gsp(nodeId=${nodeId})}" th:disabled="${nodeId=='0'}" class="btn btn-primary btn-sm" type="button">
				<i class="fa fa-plus"></i>&nbsp;新增
			</button>
		</div>
		<div class="col-md-4">
			<input type="hidden" id="nodeId" th:value="${nodeId}" />
			<div class="input-group">
				<input name="simpleQueryParam" type="text" placeholder="请输入关键字搜索" class="form-control" /> <span class="input-group-btn">
					<button onclick="myTable.filter()" type="button" class="btn btn-sm btn-primary">搜索</button>
				</span>
			</div>
		</div>
	</div>
</header>
<table id="infoDataTable" class="table table-striped table-hover">
	<thead>
		<tr>
			<th width="60" class="text-center">#</th>
			<th>状态</th>
			<th>所属栏目</th>
			<th>主标题</th>
			<th class="text-center">发布日期</th>
			<th class="text-center">创建者</th>
			<th class="text-center">排序</th>
			<th class="text-center">浏览总数</th>
			<th width="120" class="text-center">操作</th>
		</tr>
	</thead>
	<tbody id="dataTableDiv">
	</tbody>
</table>
<script th:inline="javascript">
    /*<![CDATA[*/
    //表格
    var myTable;
    //表格列定义
    var columnDefs = [ {
        //第一列，用来显示序号
        "searchable" : false,
        "orderable" : false,
        "targets" : 0
    } ];
    var columns = [ {
        //第一列，用来显示序号
        "data" : null,
        "class" : "text-center"
    }, {
        "data" : "state",
        render : function(data, type, row, meta) {
            if (data === 1) {
                return '<span class="text-success">已发布</span>';
            } else {
                return '<span class="text-danger">未发布</span>';
            }
        }
    }, {
        "data" : "nodeName"
    }, {
        "data" : "title"
    }, {
        "data" : "publishTime",
        "class" : "text-center"
    }, {
        "data" : "createDataUsername",
        "class" : "text-center"
    }, {
        "data" : "sortOrder",
        "class" : "text-center"
    }, {
        "data" : "viewsCount",
        "class" : "text-center"
    }, {
        "data" : null,
        "class" : "text-center", //最后一列，操作按钮
        render : function(data, type, row, meta) {
            var editUrl = /*[[@{/admin/m/base/info/edit_{id}.gsp}]]*/'';
            var result = '<button href="' + editUrl.replace("{id}", row.id) + '" onclick="loadEditInfo(this)" class="btn btn-primary btn-xs"><i class="fa fa-pencil"></i></button>';
            //删除按钮
            result += ' <a href="#" type="button" onclick="myTable.deleteItem(\'' + row.id + '\')" class="btn btn-danger btn-xs"><i class="fa fa-trash-o"></i></a>';
            return result;
        }
    } ];
    //ajax参数
    var ajaxDataParamFun = function(d) {
        d.simpleQueryParam = $('#simpleQueryParam').val(); //模糊查询
        d.nodeId = $('#nodeId').val() == '0' ? '' : $('#nodeId').val();
    };
    //表格setting
    var setting = {
        listUrl : /*[[@{/admin/m/base/info/list.gsp}]]*/'url',
        deleteUrl : /*[[@{/admin/m/base/info/delete_}]]*/'url',
        enableUrl : /*[[@{/admin/m/base/info/enable_}]]*/'url',
        disableUrl : /*[[@{/admin/m/base/info/disable_}]]*/'url',
        columnDefs : columnDefs, //表格列定义
        columns : columns, //表格列
        dataTableDiv : 'infoDataTable', //表格
        ajaxDataParamFun : ajaxDataParamFun, //ajax参数
        pageable : true, //是否分页
        showIndexColumn : true, //是否显示第一列的索引列
        enabledChange : false
    };
    //创建表格
    myTable = new TG_Tabel.createNew(setting);
    //加载完成后执行
    $(function() {
        //表格初始化
        myTable.init();
    });

    $('#infoAddBtn').click(function() {
        $("#infoContent").load($(this).attr('href'));
    });
    function loadEditInfo(obj) {
        $("#infoContent").load($(obj).attr('href'));
    }
    /*]]>*/
</script>
